#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctime>

#include "kahansum.h"
#include "median.h"
#include "Vector.h"
#include "utils.h"
#include "SangerRule.h"
using namespace std;

int main()
{
	vector<DMVector> vlist, outlist;
	vector<int> vp;
	int i, j, k;
	srand( (unsigned)time( NULL ) );

	string filename = "iris-flower";	//defalut filename
	string outfile = "out-1-1";			//defalut outputname
	vector<DMVector> W;
	
	cout << "input: inputfile, outputfile, target dimension num:" << endl;
	cin >> filename >> outfile >> k;
	vlist = read_data ( filename );
	
	vector<double> vmean = vector_mean ( vlist );
	int size = vlist.size();
	int sj = vlist[0].size();
	DMVector tmpX;
	
	for ( i = 0; i < size; ++i )
	{
		for ( j = 0; j < sj; ++j )
		{
			vlist[i].set ( j, vlist[i].get ( j ) - vmean[j] );
		}
	}
	
	SangerRule srule ( k, vlist[0].size(), 0.01 );
	srule.init();
	for ( i = 0; i < 10000; ++i )
	{
		srule.update ( vlist[rand() % size] );
	}
	
	W = srule.getW();
	
	outlist.resize( size );
	for ( i = 0; i < size; ++i )
	{	
		tmpX = vlist[i];
		for ( j = 0; j < 2; ++j )
		{
			outlist[i].set ( j, W[j].dot ( tmpX ));
		}
	}
	
	write_data ( outfile, outlist );

	return 0;
}
